package com.cskaoyan.service;


import com.cskaoyan.bo.ConfigExpressBo;
import com.cskaoyan.bo.ConfigMallBo;
import com.cskaoyan.bo.ConfigOrderBo;
import com.cskaoyan.bo.ConfigWXBo;

import com.cskaoyan.mapper.ConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther hhy
 */
@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    ConfigMapper configMapper;
    @Override
    public Map selectMallConfig(String condition) {
        List<Map> maps = configMapper.selectMallConfig(condition);
        Map<String,String> resultMap = new HashMap<>();
        for (Map map : maps) {
            String key = (String) map.get("key");
            //将cskaoyan_mall变成cskaoyanmall
            int i = key.indexOf("_");
            key = key.substring(0,i) + key.substring(i+1);
            resultMap.put(key,(String)map.get("value"));
        }
        return resultMap;
    }

    @Override
    public void updateConfigMall(ConfigMallBo configMallBO) {
        Timestamp timestamp = new Timestamp(new Date().getTime());
        configMapper.updateConfigMall(configMallBO.getCskaoyanmall_mall_address(),
                timestamp,"cskaoyan_mall_mall_address");
        configMapper.updateConfigMall(configMallBO.getCskaoyanmall_mall_name(),
                timestamp,"cskaoyan_mall_mall_name");
        configMapper.updateConfigMall(configMallBO.getCskaoyanmall_mall_phone(),
                timestamp,"cskaoyan_mall_mall_phone");
        configMapper.updateConfigMall(configMallBO.getCskaoyanmall_mall_qq(),
                timestamp,"cskaoyan_mall_mall_qq");
    }

    @Override
    public void updateConfigExpress(ConfigExpressBo configExpressBo) {
        Timestamp timestamp = new Timestamp(new Date().getTime());
        configMapper.updateConfigExpress(configExpressBo.getCskaoyanmall_express_freight_min(),
                timestamp,"cskaoyan_mall_express_freight_min");
        configMapper.updateConfigExpress(configExpressBo.getCskaoyanmall_express_freight_value(),
                timestamp,"cskaoyan_mall_express_freight_value");
    }

    @Override
    public void updateConfigOrder(ConfigOrderBo configOrderBo) {
        Timestamp timestamp = new Timestamp(new Date().getTime());
        configMapper.updateConfigOrder(configOrderBo.getCskaoyanmall_order_comment(),
                timestamp,"cskaoyan_mall_order_comment");
        configMapper.updateConfigOrder(configOrderBo.getCskaoyanmall_order_unconfirm(),
                timestamp,"cskaoyan_mall_order_unconfirm");
        configMapper.updateConfigOrder(configOrderBo.getCskaoyanmall_order_unpaid(),
                timestamp,"cskaoyan_mall_order_unpaid");

    }

    @Override
    public void updateConfigWX(ConfigWXBo configWXBo) {
        Timestamp timestamp = new Timestamp(new Date().getTime());
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_catlog_goods(),
                timestamp,"cskaoyan_mall_wx_catlog_goods");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_catlog_list(),
                timestamp,"cskaoyan_mall_wx_catlog_list");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_index_brand(),
                timestamp,"cskaoyan_mall_wx_index_brand");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_index_hot(),
                timestamp,"cskaoyan_mall_wx_index_hot");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_index_new(),
                timestamp,"cskaoyan_mall_wx_index_new");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_index_topic(),
                timestamp,"cskaoyan_mall_wx_index_topic");
        configMapper.updateConfigWX(configWXBo.getCskaoyanmall_wx_share(),
                timestamp, "cskaoyan_mall_wx_share");
    }


}
